{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "187819b1",
   "metadata": {},
   "source": [
    "## 创建人脸数据库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3c18d594",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': 'd938dbef810dd4277fc7ac99bbdb4c7e', 'time_used': 201, 'face_count': 0, 'face_added': 0, 'request_id': '1679317148,1c268761-b86a-4716-8090-a5e0781d3d04', 'outer_id': '', 'failure_detail': []}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "\n",
    "'''\n",
    "人脸数据库创建\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "# 请求参数\n",
    "params = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'display_name':\"广州南方学院21栋宿舍楼\"\n",
    "}\n",
    "\n",
    "response = requests.post(request_url, data=params)\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3fda17fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': 'b5138d7eed29881af5926b87e542796f', 'tags': '', 'time_used': 105, 'user_data': '', 'display_name': '广州南方学院21栋宿舍楼', 'face_tokens': [], 'face_count': 0, 'request_id': '1679317150,c2805160-e026-43ad-b3e8-a45499886dfa', 'outer_id': ''}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "\n",
    "'''\n",
    "人脸数据库创建\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "# 请求参数\n",
    "params = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'faceset_token':\"b5138d7eed29881af5926b87e542796f\"\n",
    "}\n",
    "\n",
    "response = requests.post(request_url, data=params)\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f31ed305",
   "metadata": {},
   "source": [
    "## 检测人脸信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e0e81978",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679317154,f00be6b3-9a3c-4393-8ddf-e6787c8a583d', 'time_used': 131, 'faces': [{'face_token': '2c86ebbf24fc25b8c3d563bc2ce351d2', 'face_rectangle': {'top': 103, 'left': 158, 'width': 102, 'height': 102}}], 'image_id': '8GsTECQOWBVEZIdykh49eg==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# 检测人脸信息\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测:刘亦菲，王俊凯，赵露思，章若楠\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('21栋/lyf.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'image_base64':img,\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c0d8f377",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679317156,b8aea649-3277-42ae-af85-c3d52cd646e5', 'time_used': 47, 'faces': [{'face_token': 'bb1bbe0ce0b43cc472cbd759db8d5e18', 'face_rectangle': {'top': 237, 'left': 124, 'width': 119, 'height': 119}}], 'image_id': 'LbLE8dUZaRKioQXBSiK8WA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# 检测人脸信息\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测:刘亦菲，王俊凯，赵露思，章若楠\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('21栋/wjk.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'image_base64':img,\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a0ac361b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679317160,af4c711c-71b0-4daf-8526-8a111fecb956', 'time_used': 184, 'faces': [{'face_token': '0e6ef71d93a4a32711799b3838d18988', 'face_rectangle': {'top': 80, 'left': 222, 'width': 87, 'height': 87}}, {'face_token': '76e74f66b30e390633546e0227cf361e', 'face_rectangle': {'top': 341, 'left': 185, 'width': 44, 'height': 44}}], 'image_id': 'liHMxnapcyVzHF6LzQR7MA==', 'face_num': 2}\n"
     ]
    }
   ],
   "source": [
    "# 检测人脸信息\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测:刘亦菲，王俊凯，赵露思，章若楠\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('21栋/zls.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'image_base64':img,\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "dd338d8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679317163,86f153f6-8ed7-49fc-ae3b-3cfe53488e56', 'time_used': 40, 'faces': [{'face_token': '5b68da9edc51461d746daa97e3dacf25', 'face_rectangle': {'top': 221, 'left': 134, 'width': 234, 'height': 234}}], 'image_id': 'GQOMGFIDp+/gwi8VRPe8AQ==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# 检测人脸信息\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测:刘亦菲，王俊凯，赵露思，章若楠\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('21栋/zrn.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'image_base64':img,\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f843571",
   "metadata": {},
   "source": [
    "## 增加人脸"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c72269c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 4041a04ee15d4d61a6113bc54a26dfa1 53265a4527f8b2cb787a10ba9cad1870 7885b3bbfc7aa4623d0ce28b704ed993 6fe4de2cda21a6586e34cdcd6d412f53"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "72b6f297",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': '0e561d5092917085e1cb2118dabe90c4', 'time_used': 104, 'face_count': 5, 'face_added': 0, 'request_id': '1679317167,040ca7ef-4ed1-4b07-8c4f-078c6f796ba7', 'outer_id': '', 'failure_detail': []}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "'''\n",
    "增加人脸\n",
    "'''\n",
    "request_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "# 请求参数\n",
    "params = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'faceset_token':\"0e561d5092917085e1cb2118dabe90c4\",\n",
    "    'face_tokens':'4041a04ee15d4d61a6113bc54a26dfa1'\n",
    "\n",
    "}\n",
    "\n",
    "response = requests.post(request_url, data=params)\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d312a9c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2f9904c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
